package com.hb.core.base;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @description: 分页查询响应
 * @projectName: zhb-frame-build
 * @author: zhouhaizhi
 * @createTime: 2021/8/16 15:13
 * @version:1.0
 */
@Getter
@Setter
public class PageDataInfo<T> implements Serializable {

    /*
        总记录数
     */
    private Long total;

    /*
        列表总体的页数
     */
    private Integer totalPage;

    /*
        列表数据
     */
    private List<T> content;

    public static PageDataInfo EMPTY;

    static {
        EMPTY = new PageDataInfo(new ArrayList(), 0L);
    }

    public PageDataInfo() {
    }

    public PageDataInfo(List<T> list, long total) {
        this.content = list;
        this.total = total;
    }

    public PageDataInfo(List<T> list, long total, int totalPage) {
        this.content = list;
        this.total = total;
        this.totalPage = totalPage;
    }

    public <E> PageDataInfo<E> convertTo(Class<E> clazz) {
        PageDataInfo<E> pageDataInfo = new PageDataInfo<>();
        pageDataInfo.setContent((List<E>) this.content);
        pageDataInfo.setTotal(this.total);
        return pageDataInfo;
    }
}
